﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Threading;
using System.Globalization;
using System.Web;
using MvcEngine.Core;
using MvcEngine.Core.Utils;
using MvcEngine.Mvc.Models.ViewModels;
using MvcEngine.Core.Localization;
using MvcEngine.Core.Helpers;

namespace MvcEngine.Mvc.Filters
{
    public class LanguageActionFilter : IActionFilter
    {
        #region IActionFilter Members

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            MvcEngineModel model = filterContext.Controller.ViewData.Model as MvcEngineModel;
            if (model == null) return;

            //model.AddModelItem(new MvcEngineModelItem<SelectList>()
            //{
            //    Item = new SelectList(LocalizationUtil.GetLanguages(),
            //        "ShortName",
            //        "Name",
            //        Thread.CurrentThread.CurrentCulture.ToString())
            //});

            //model.SetModelValue("CurrentLanguage", Thread.CurrentThread.CurrentCulture.ToString());
        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            LocalizationUtil.SetThreadLanguage(filterContext.HttpContext.Request);
        }


        #endregion
    }
}
